﻿using System.Reflection;

namespace Borg
{
    internal class PlugUnplugTask : Task<PlugInfo>
    {
        private readonly SlotInfo _si;

        public override string Name
        {
            get
            {
                return _si == null
                    ? string.Format("Unplug({0})", obj.Name)
                    : string.Format("Unplug({0}, {1})", obj.Name, _si.Name);
            }
        }

        public PlugUnplugTask(PlugInfo obj, SlotInfo si, uint taskGroupId, Assembly initiator)
            : base(obj, taskGroupId, initiator)
        {
            _si = si;
        }

        public override void Execute()
        {
            if (_si == null)
                obj.InternalUnplug(initiator, false);
            else
                _si.InternalUnplug(obj, initiator, false);
        }

        public override string ToString()
        {
            return _si == null
                ? string.Format("{0}: {1}.InternalUnplug()", taskGroupId, obj)
                : string.Format("{0}: {1}.InternalUnplug({2})", taskGroupId, obj, _si);
        }
    }
}

